home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / stl / stl_set.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-08  |  9.2 KB  |  269 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Permission to use, copy, modify, distribute and sell this software
  7.  * and its documentation for any purpose is hereby granted without fee,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.  Hewlett-Packard Company makes no
  11.  * representations about the suitability of this software for any
  12.  * purpose.  It is provided "as is" without express or implied warranty.
  13.  *
  14.  *
  15.  * Copyright (c) 1996,1997
  16.  * Silicon Graphics Computer Systems, Inc.
  17.  *
  18.  * Permission to use, copy, modify, distribute and sell this software
  19.  * and its documentation for any purpose is hereby granted without fee,
  20.  * provided that the above copyright notice appear in all copies and
  21.  * that both that copyright notice and this permission notice appear
  22.  * in supporting documentation.  Silicon Graphics makes no
  23.  * representations about the suitability of this software for any
  24.  * purpose.  It is provided "as is" without express or implied warranty.
  25.  */
  26.  
  27. /* NOTE: This is an internal header file, included by other STL headers.
  28.  *   You should not attempt to use it directly.
  29.  */
  30.  
  31. #ifndef __SGI_STL_INTERNAL_SET_H
  32. #define __SGI_STL_INTERNAL_SET_H
  33.  
  34. #include <concept_checks.h>
  35.  
  36. __STL_BEGIN_NAMESPACE
  37.  
  38. #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
  39. #pragma set woff 1174
  40. #pragma set woff 1375
  41. #endif
  42.  
  43. // Forward declarations of operators < and ==, needed for friend declaration.
  44.  
  45. template <class _Key, class _Compare __STL_DEPENDENT_DEFAULT_TMPL(less<_Key>),
  46.           class _Alloc = __STL_DEFAULT_ALLOCATOR(_Key) >
  47. class set;
  48.  
  49. template <class _Key, class _Compare, class _Alloc>
  50. inline bool operator==(const set<_Key,_Compare,_Alloc>& __x, 
  51.                        const set<_Key,_Compare,_Alloc>& __y);
  52.  
  53. template <class _Key, class _Compare, class _Alloc>
  54. inline bool operator<(const set<_Key,_Compare,_Alloc>& __x, 
  55.                       const set<_Key,_Compare,_Alloc>& __y);
  56.  
  57.  
  58. template <class _Key, class _Compare, class _Alloc>
  59. class set {
  60.   // requirements:
  61.  
  62.   __STL_CLASS_REQUIRES(_Key, _Assignable);
  63.   __STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Key, _Key);
  64.  
  65. public:
  66.   // typedefs:
  67.  
  68.   typedef _Key     key_type;
  69.   typedef _Key     value_type;
  70.   typedef _Compare key_compare;
  71.   typedef _Compare value_compare;
  72. private:
  73.   typedef _Rb_tree<key_type, value_type, 
  74.                   _Identity<value_type>, key_compare, _Alloc> _Rep_type;
  75.   _Rep_type _M_t;  // red-black tree representing set
  76. public:
  77.   typedef typename _Rep_type::const_pointer pointer;
  78.   typedef typename _Rep_type::const_pointer const_pointer;
  79.   typedef typename _Rep_type::const_reference reference;
  80.   typedef typename _Rep_type::const_reference const_reference;
  81.   typedef typename _Rep_type::const_iterator iterator;
  82.   typedef typename _Rep_type::const_iterator const_iterator;
  83.   typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
  84.   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
  85.   typedef typename _Rep_type::size_type size_type;
  86.   typedef typename _Rep_type::difference_type difference_type;
  87.   typedef typename _Rep_type::allocator_type allocator_type;
  88.  
  89.   // allocation/deallocation
  90.  
  91.   set() : _M_t(_Compare(), allocator_type()) {}
  92.   explicit set(const _Compare& __comp,
  93.                const allocator_type& __a = allocator_type())
  94.     : _M_t(__comp, __a) {}
  95.  
  96. #ifdef __STL_MEMBER_TEMPLATES
  97.   template <class _InputIterator>
  98.   set(_InputIterator __first, _InputIterator __last)
  99.     : _M_t(_Compare(), allocator_type())
  100.     { _M_t.insert_unique(__first, __last); }
  101.  
  102.   template <class _InputIterator>
  103.   set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
  104.       const allocator_type& __a = allocator_type())
  105.     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
  106. #else
  107.   set(const value_type* __first, const value_type* __last) 
  108.     : _M_t(_Compare(), allocator_type()) 
  109.     { _M_t.insert_unique(__first, __last); }
  110.  
  111.   set(const value_type* __first, 
  112.       const value_type* __last, const _Compare& __comp,
  113.       const allocator_type& __a = allocator_type())
  114.     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
  115.  
  116.   set(const_iterator __first, const_iterator __last)
  117.     : _M_t(_Compare(), allocator_type()) 
  118.     { _M_t.insert_unique(__first, __last); }
  119.  
  120.   set(const_iterator __first, const_iterator __last, const _Compare& __comp,
  121.       const allocator_type& __a = allocator_type())
  122.     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
  123. #endif /* __STL_MEMBER_TEMPLATES */
  124.  
  125.   set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
  126.   set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
  127.   { 
  128.     _M_t = __x._M_t; 
  129.     return *this;
  130.   }
  131.  
  132.   // accessors:
  133.  
  134.   key_compare key_comp() const { return _M_t.key_comp(); }
  135.   value_compare value_comp() const { return _M_t.key_comp(); }
  136.   allocator_type get_allocator() const { return _M_t.get_allocator(); }
  137.  
  138.   iterator begin() const { return _M_t.begin(); }
  139.   iterator end() const { return _M_t.end(); }
  140.   reverse_iterator rbegin() const { return _M_t.rbegin(); } 
  141.   reverse_iterator rend() const { return _M_t.rend(); }
  142.   bool empty() const { return _M_t.empty(); }
  143.   size_type size() const { return _M_t.size(); }
  144.   size_type max_size() const { return _M_t.max_size(); }
  145.   void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
  146.  
  147.   // insert/erase
  148.   pair<iterator,bool> insert(const value_type& __x) { 
  149.     pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x); 
  150.     return pair<iterator, bool>(__p.first, __p.second);
  151.   }
  152.   iterator insert(iterator __position, const value_type& __x) {
  153.     typedef typename _Rep_type::iterator _Rep_iterator;
  154.     return _M_t.insert_unique((_Rep_iterator&)__position, __x);
  155.   }
  156. #ifdef __STL_MEMBER_TEMPLATES
  157.   template <class _InputIterator>
  158.   void insert(_InputIterator __first, _InputIterator __last) {
  159.     _M_t.insert_unique(__first, __last);
  160.   }
  161. #else
  162.   void insert(const_iterator __first, const_iterator __last) {
  163.     _M_t.insert_unique(__first, __last);
  164.   }
  165.   void insert(const value_type* __first, const value_type* __last) {
  166.     _M_t.insert_unique(__first, __last);
  167.   }
  168. #endif /* __STL_MEMBER_TEMPLATES */
  169.   void erase(iterator __position) { 
  170.     typedef typename _Rep_type::iterator _Rep_iterator;
  171.     _M_t.erase((_Rep_iterator&)__position); 
  172.   }
  173.   size_type erase(const key_type& __x) { 
  174.     return _M_t.erase(__x); 
  175.   }
  176.   void erase(iterator __first, iterator __last) { 
  177.     typedef typename _Rep_type::iterator _Rep_iterator;
  178.     _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); 
  179.   }
  180.   void clear() { _M_t.clear(); }
  181.  
  182.   // set operations:
  183.  
  184.   iterator find(const key_type& __x) const { return _M_t.find(__x); }
  185.   size_type count(const key_type& __x) const {
  186.     return _M_t.find(__x) == _M_t.end() ? 0 : 1;
  187.   }
  188.   iterator lower_bound(const key_type& __x) const {
  189.     return _M_t.lower_bound(__x);
  190.   }
  191.   iterator upper_bound(const key_type& __x) const {
  192.     return _M_t.upper_bound(__x); 
  193.   }
  194.   pair<iterator,iterator> equal_range(const key_type& __x) const {
  195.     return _M_t.equal_range(__x);
  196.   }
  197.  
  198. #ifdef __STL_TEMPLATE_FRIENDS
  199.   template <class _K1, class _C1, class _A1>
  200.   friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
  201.   template <class _K1, class _C1, class _A1>
  202.   friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
  203. #else /* __STL_TEMPLATE_FRIENDS */
  204.   friend bool __STD_QUALIFIER
  205.   operator== __STL_NULL_TMPL_ARGS (const set&, const set&);
  206.   friend bool __STD_QUALIFIER
  207.   operator<  __STL_NULL_TMPL_ARGS (const set&, const set&);
  208. #endif /* __STL_TEMPLATE_FRIENDS */
  209. };
  210.  
  211. template <class _Key, class _Compare, class _Alloc>
  212. inline bool operator==(const set<_Key,_Compare,_Alloc>& __x, 
  213.                        const set<_Key,_Compare,_Alloc>& __y) {
  214.   return __x._M_t == __y._M_t;
  215. }
  216.  
  217. template <class _Key, class _Compare, class _Alloc>
  218. inline bool operator<(const set<_Key,_Compare,_Alloc>& __x, 
  219.                       const set<_Key,_Compare,_Alloc>& __y) {
  220.   return __x._M_t < __y._M_t;
  221. }
  222.  
  223. #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
  224.  
  225. template <class _Key, class _Compare, class _Alloc>
  226. inline bool operator!=(const set<_Key,_Compare,_Alloc>& __x, 
  227.                        const set<_Key,_Compare,_Alloc>& __y) {
  228.   return !(__x == __y);
  229. }
  230.  
  231. template <class _Key, class _Compare, class _Alloc>
  232. inline bool operator>(const set<_Key,_Compare,_Alloc>& __x, 
  233.                       const set<_Key,_Compare,_Alloc>& __y) {
  234.   return __y < __x;
  235. }
  236.  
  237. template <class _Key, class _Compare, class _Alloc>
  238. inline bool operator<=(const set<_Key,_Compare,_Alloc>& __x, 
  239.                        const set<_Key,_Compare,_Alloc>& __y) {
  240.   return !(__y < __x);
  241. }
  242.  
  243. template <class _Key, class _Compare, class _Alloc>
  244. inline bool operator>=(const set<_Key,_Compare,_Alloc>& __x, 
  245.                        const set<_Key,_Compare,_Alloc>& __y) {
  246.   return !(__x < __y);
  247. }
  248.  
  249. template <class _Key, class _Compare, class _Alloc>
  250. inline void swap(set<_Key,_Compare,_Alloc>& __x, 
  251.                  set<_Key,_Compare,_Alloc>& __y) {
  252.   __x.swap(__y);
  253. }
  254.  
  255. #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
  256.  
  257. #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
  258. #pragma reset woff 1174
  259. #pragma reset woff 1375
  260. #endif
  261.  
  262. __STL_END_NAMESPACE
  263.  
  264. #endif /* __SGI_STL_INTERNAL_SET_H */
  265.  
  266. // Local Variables:
  267. // mode:C++
  268. // End:
  269.